//
//  THJDianJiaInfoVC.m
//  THJXHW
//
//  Created by 河南德艺 on 2018/9/17.
//  Copyright © 2018年 河南德艺. All rights reserved.
//

#import "THJDianJiaInfoVC.h"
#import "THJDIanjiaXieYiVC.h"

@interface THJDianJiaInfoVC ()
{
    //同意协议
    BOOL accept;
}

@property (weak, nonatomic) IBOutlet UILabel *priceLab;

@property (weak, nonatomic) IBOutlet UILabel *tunLab;
@property (weak, nonatomic) IBOutlet UILabel *heyueLabel;
@property (weak, nonatomic) IBOutlet UILabel *guigeLabel;
@property (weak, nonatomic) IBOutlet UILabel *areaLabel;
@property (weak, nonatomic) IBOutlet UILabel *cangkuLabel;
@property (weak, nonatomic) IBOutlet UILabel *addressLabel;
@property (weak, nonatomic) IBOutlet UILabel *kucunLabel;
@property (weak, nonatomic) IBOutlet UITextField *tf4;
@property (weak, nonatomic) IBOutlet UITextField *tf1;
@property (weak, nonatomic) IBOutlet UITextField *tf2;
@property (weak, nonatomic) IBOutlet UITextField *tf3;
@property (weak, nonatomic) IBOutlet UIButton *sureBtn;


@end

@implementation THJDianJiaInfoVC
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden = YES;
    [self setStateBarColor:COLOR(21, 21, 21, 1)];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    accept = NO;
    NSLog(@"传过来的数据:%@",self.infoDic);
    self.priceLab.text = self.infoDic[@"pro_name"];
   
    self.tunLab.text = [self.infoDic[@"total"] isEqual:@"0"] ? @"卖":@"买";
    self.heyueLabel.text = self.infoDic[@"heyue"];
    self.guigeLabel.text = self.infoDic[@"guige"];
    self.areaLabel.text = self.infoDic[@"area_name"];
    self.cangkuLabel.text = self.infoDic[@"house"];
    self.addressLabel.text = self.infoDic[@"address"];
    self.kucunLabel.text = [NSString stringWithFormat:@"%ld吨",[self.infoDic[@"total"] integerValue]];
    
    self.tf1.keyboardType = self.tf3.keyboardType = self.tf4.keyboardType = UIKeyboardTypeNumberPad;
    self.tf1.attributedPlaceholder = [[NSAttributedString  alloc]initWithString:@"请输入采购吨数"attributes:@{NSForegroundColorAttributeName:COLOR(80, 80, 80, 1)}];
    self.tf2.attributedPlaceholder = [[NSAttributedString  alloc]initWithString:@"请输入联系人"attributes:@{NSForegroundColorAttributeName:COLOR(80, 80, 80, 1)}];
    self.tf3.attributedPlaceholder = [[NSAttributedString  alloc]initWithString:@"请输入联系电话"attributes:@{NSForegroundColorAttributeName:COLOR(80, 80, 80, 1)}];
    self.tf4.attributedPlaceholder = [[NSAttributedString  alloc]initWithString:@"请输入点价金额"attributes:@{NSForegroundColorAttributeName:COLOR(80, 80, 80, 1)}];
}
- (IBAction)backBtnAction:(id)sender {
    [self pop];
}
- (IBAction)tradeBtnAction:(id)sender {
   
        if([self.tf1.text integerValue] == 0 || self.tf1.text.length == 0){
            [self HUDShowMsg:@"请输入采购数量" AfterDelayDimiss:1];
        }else if([self.tf4.text integerValue] == 0 || self.tf4.text.length == 0){
            [self HUDShowMsg:@"请输入点价金额" AfterDelayDimiss:1];
        }else if(self.tf2.text.length == 0){
            [self HUDShowMsg:@"请输入联系人" AfterDelayDimiss:1];
        }else if(self.tf2.text.length == 0){
            [self HUDShowMsg:@"请输入联系人" AfterDelayDimiss:1];
        }else if(self.tf3.text.length == 0){
            [self HUDShowMsg:@"请输入联系电话" AfterDelayDimiss:1];
        }else if(self.tf3.text.length != 11){
            [self HUDShowMsg:@"请输入正确电话号码" AfterDelayDimiss:1];
        }else{
            if(!accept){
                 [self HUDShowMsg:@"同意点价协议才能继续交易" AfterDelayDimiss:1];
            }else{
                NSString * url = @"https://dianjia.thjb.net/dingjia.php?f=Member&r=Member&m=zhan";
                NSDictionary * para = @{
                                        @"price":self.tf4.text,
                                        @"sell_id":self.infoDic[@"id"],
                                        @"number":self.tf1.text,
                                        @"truename":self.tf2.text,
                                        @"mobile":self.tf3.text
                                        };
                [THJNetWork postDataFromUrl:url parameters:para Token:[THJTools getToken] callback:^(NSDictionary* receiveData, NSError *error) {
                    NSLog(@"点价确定---%@",receiveData);
                    if([receiveData[@"status"] isEqual:@"200"]){
                        [self HUDShowMsg:receiveData[@"tip"] AfterDelayDimiss:1];
                        [self performSelector:@selector(pop) withObject:nil afterDelay:1];
                    }else{
                        [self HUDShowMsg:receiveData[@"tip"] AfterDelayDimiss:1];
                    }
                }];
            }
        }
}
//点价协议按钮
- (IBAction)dianjiaXieyiAction:(id)sender {
    [self presentViewController:[THJDIanjiaXieYiVC new] animated:YES completion:nil];
}
//同意协议按钮
- (IBAction)sureBtnAction:(id)sender {
    
    if(accept){
        accept = NO;
        [self.sureBtn setImage:kGetImage(@"不同意") forState:UIControlStateNormal];
    }else{
        accept = YES;
        [self.sureBtn setImage:kGetImage(@"同意") forState:UIControlStateNormal];
    }
}
@end
